package com.hnevc.androidhomework2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    //1.要用到的控件，
    EditText mEtHeight;//身高控件
    RadioGroup mRgSex;//性别控件
    Button mBtnComputer;//计算按钮控件
    TextView mTvResult;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //从界面中找到控件，保存到成员变量中
        mEtHeight=findViewById(R.id.et_height);
        mBtnComputer=findViewById(R.id.btn_compute);
        mRgSex=findViewById(R.id.rg_sex);
        mBtnComputer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String sHeight=mEtHeight.getText().toString();
                int height=Integer.parseInt(sHeight);
                int height2=Integer.parseInt(mEtHeight.getText().toString());

                int  id=mRgSex.getCheckedRadioButtonId();
                if (id==R.id.rb_male){
                    int standarWeight=(int)((height-100)*0.9);
                   // mTvResult.setText("标准体重是"+standarWeight+"KG");
                    Toast.makeText(MainActivity.this, "标准体重是"+standarWeight+"KG", Toast.LENGTH_SHORT).show();
                }else if(id==R.id.rb_female){
                    int standarWeight=(int)((height-100)*0.9-2.5);
                    mTvResult.setText("标准体重是"+standarWeight+"KG");
                }
            }
        });
    }
}
